package com.purong.purong.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;


import com.purong.purong.R;
import com.purong.purong.adapter.SchedulePagerAdapter;
import com.purong.purong.fragment.MyScheduleFragment;
import com.purong.purong.fragment.QueryScheduleFragment;

import java.util.ArrayList;

/**
 * Created by wenjiezeng on 2017/9/28.
 * 进度查询
 */
public class ScheduleQueryActivity extends BaseActivity{
    private ViewPager mViewPager;
    private SchedulePagerAdapter mAdapter;
    private TextView myScheduleTv,queryScheduleTv;
    private ArrayList<Fragment> fragmentList=new ArrayList<>();



    @Override
    public int getRootViewId() {
        return R.layout.activity_schedule_query;
    }

    public void initView(){
        myScheduleTv=(TextView)findViewById(R.id.my_schedule);
        queryScheduleTv=(TextView)findViewById(R.id.query_schedule);
        mViewPager=(ViewPager)findViewById(R.id.view_pager);

        MyScheduleFragment scheduleQueryFragment=new MyScheduleFragment();
        fragmentList.add(scheduleQueryFragment);
        QueryScheduleFragment myScheduleFragment=new QueryScheduleFragment();
        fragmentList.add(myScheduleFragment);
        mAdapter=new SchedulePagerAdapter(getSupportFragmentManager(),fragmentList);
        mViewPager.setAdapter(mAdapter);
        mViewPager.setOffscreenPageLimit(2);
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (position==0){
                    myScheduleTv.setTextColor(getResources().getColor(R.color.text_dark_gray));
                    queryScheduleTv.setTextColor(getResources().getColor(R.color.text_gray));
                }else if (position==1){
                    myScheduleTv.setTextColor(getResources().getColor(R.color.text_gray));
                    queryScheduleTv.setTextColor(getResources().getColor(R.color.text_dark_gray));
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    public void initData() {

    }

    public void onClick(View v){
        switch (v.getId()){
            case R.id.left_back:
                this.finish();
                break;
            case R.id.my_schedule:
                mViewPager.setCurrentItem(0);
                break;
            case R.id.query_schedule:
                mViewPager.setCurrentItem(1);
                break;
        }
    }
}
